
var SELFID = getCookie("openId");
// var SELFID = 'oJEP8t_rnBFzEfuA-fqwDKdWbytA' || 'oJEP8t3lOErHAb1nHabl21PIJkJU';

var HOST = 'https://worldcup.dmpb.com.cn';
var VERSON = 'v1.2';
var pageType = document.location.pathname.split('/').pop();

if (!SELFID && ['strategy.html','house_list.html','wxgroup.html'].indexOf(pageType) < 0) {
	console.log(2333);
	window.location = HOST + '/weixin_logic';
}

function getCookie(key){//获取cookie方法
	/*获取cookie参数*/
	var getCookie = document.cookie.replace(/[ ]/g,"");  //获取cookie，并且将获得的cookie格式化，去掉空格字符
	var arrCookie = getCookie.split(";")  //将获得的cookie以"分号"为标识 将cookie保存到arrCookie的数组中
	var tips;  //声明变量tips
	for(var i=0;i<arrCookie.length;i++){   //使用for循环查找cookie中的tips变量
		var arr=arrCookie[i].split("=");   //将单条cookie用"等号"为标识，将单条cookie保存为arr数组
		if(key==arr[0]){  //匹配变量名称，其中arr[0]是指的cookie名称，如果该条变量为tips则执行判断语句中的赋值操作
			tips=arr[1];   //将cookie的值赋给变量tips
			break;   //终止for循环遍历
		} 
	}
	return tips;
}

function parseUrlSearch(){
	var search = location.search;
	if(!search) {
		return {};
	}
	search = search.slice(1).split('&');
	var data = {};
	search.forEach(function(item) {
		item = item.split('=');
		data[item[0]] = item[1]; 
	});
	return data;
}

// return: 1|val1<val2, 3|val1>val2, 2|val1=val2;
function compareDate(val1, val2){
	val1 = val1.split('-');
	val2 = val2.split('-');
	for(var i = 0 ;i < 3; i++) {
		if(+val1[i] < +val2[i]) {
			return 1;
		}
		if(+val1[i] > +val2[i]) {
			return 3;
		}
	}
	return 2;
}

var throttle = function (fn, delay, atleast) {
	delay = delay || 0;
	var timer = null;
	var previous = null;

	return function (e) {
		var now = +new Date();

		if ( !previous ) previous = now;

		if ( now - previous > atleast ) {
			fn(e);
			// 重置上一次开始时间为本次结束时间
			previous = now;
		} else {
			clearTimeout(timer);
			timer = setTimeout(function() {
				fn(e);
			}, delay);
		}
	}
};

function jsGetAge(strBirthday){         
	var returnAge;  
	var strBirthdayArr=strBirthday.split("-");  
	var birthYear = strBirthdayArr[0];  
	var birthMonth = strBirthdayArr[1];  
	var birthDay = strBirthdayArr[2];  
	  
	d = new Date();  
	var nowYear = d.getFullYear();  
	var nowMonth = d.getMonth() + 1;  
	var nowDay = d.getDate();  
	  
	if(nowYear == birthYear){  
		returnAge = 0;//同年 则为0岁  
	}  
	else{  
		var ageDiff = nowYear - birthYear ; //年之差  
		if(ageDiff > 0){  
			if(nowMonth == birthMonth) {  
				var dayDiff = nowDay - birthDay;//日之差  
				if(dayDiff < 0)  
				{  
					returnAge = ageDiff - 1;  
				}  
				else  
				{  
					returnAge = ageDiff ;  
				}  
			}  
			else  
			{  
				var monthDiff = nowMonth - birthMonth;//月之差  
				if(monthDiff < 0)  
				{  
					returnAge = ageDiff - 1;  
				}  
				else  
				{  
					returnAge = ageDiff ;  
				}  
			}  
		}  
		else  
		{  
			returnAge = -1;//返回-1 表示出生日期输入错误 晚于今天  
		}  
	}  
	return returnAge;//返回周岁年龄    
}

function parseDateStamp(stamp) {
	var d = new Date(stamp * 1000);
	var year = d.getFullYear();
	var month = d.getMonth()+1;
	var date = d.getDate();
	var hours = d.getHours();
	var min = d.getMinutes();
	return year+'-'+month+'-'+date+' '+hours+':'+min;
}

function createSelect(options){
	$(options.wrapper).picker({
		toolbarTemplate: '<header class="bar bar-nav">\
			<button class="button button-link pull-right close-picker">确定</button>\
			<h1 class="title">请选择' + (options.title||'无标题') + '</h1>\
		</header>',
		cols: [{
			textAlign: 'center',
			values: options.list
		}],
		inputReadOnly: true,
		onClose: options.onClose
	});
};

function createCalendar(options){
	options.$wrapper.calendar({
		value: options.value
	});
}

function showImg(url) {
	var frameid = 'frameimg' + Math.random();
	window.img = '<img id="img" width="100%" src=\'' + url + '?' + Math.random() + '\' /><script>window.onload = function() { parent.document.getElementById(\'' + frameid + '\').height = document.getElementById(\'img\').height+\'px\'; }<' + '/script>';
	document.write();
}

var cnzz_protocol = (("https:" == document.location.protocol) ? " https://" : " http://");
document.write(unescape("%3Cspan id='cnzz_stat_icon_1267142462'%3E%3C/span%3E%3Cscript src='" + cnzz_protocol + "s13.cnzz.com/z_stat.php%3Fid%3D1267142462%26show%3Dpic1' type='text/javascript'%3E%3C/script%3E"));
